import 'dart:io';
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:device_info_plus/device_info_plus.dart';

class PlatformUtil {
  static final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
  late String deviceName;
  late String deviceVersion;
  late String identifier;
  late dynamic deviceData;
  late String version;
  late String buildNumber;
  final isIOS = Platform.isIOS;
  final isAndroid = Platform.isAndroid;
  PlatformUtil() {
    initPlatformState();
  }
  Future<void> initPlatformState() async {
    try {
      if (kIsWeb) {
        deviceData = await deviceInfoPlugin.webBrowserInfo;
      } else {
        if (Platform.isAndroid) {
          deviceData = await deviceInfoPlugin.androidInfo;
          deviceName = deviceData.model;
          deviceVersion = deviceData.version.toString();
          identifier = deviceData.androidId; //UUID for Android
        } else if (Platform.isIOS) {
          deviceData = await deviceInfoPlugin.iosInfo;
          deviceName = deviceData.name;
          deviceVersion = deviceData.systemVersion;
          identifier = deviceData.identifierForVendor; //UUID for iOS
        } else if (Platform.isLinux) {
          deviceData = await deviceInfoPlugin.linuxInfo;
          deviceName = deviceData.name;
          deviceVersion = deviceData.version;
          identifier = deviceData.id;
        } else if (Platform.isMacOS) {
          deviceData = await deviceInfoPlugin.macOsInfo;
        } else if (Platform.isWindows) {
          deviceData = await deviceInfoPlugin.windowsInfo;
        }
      }
    } on PlatformException {
      deviceData = <String, dynamic>{
        'Error:': 'Failed to get platform version.'
      };
    }
  }
}
